package com.jacobson.huobi.common.constants

object AlarmTypeConstant {
    /** 策略推送异常记录 */
    const val VALUE_ERROR_1 = -0x101
    /** 无状态 */
    const val VALUE_NONE_1 = 0x000
    /** 启动 */
    const val VALUE_START_1 = 0x101

    /** 站稳策略一 */
    const val VALUE_STAND_1 = 0x201
    /** 站稳策略二 */
    const val VALUE_STAND_2 = 0x202

    /** 破线策略一 */
    const val VALUE_BREAK_1 = 0x301
    /** 破线策略三 */
    const val VALUE_BREAK_3 = 0x303
    /** 破线策略四 */
    const val VALUE_BREAK_4 = 0x304
    /** 破线策略五 */
    const val VALUE_BREAK_5 = 0x305
    /** 破线策略六 */
    const val VALUE_BREAK_6 = 0x306
    /** 破线策略七 */
    const val VALUE_BREAK_7 = 0x307
    /** 破线策略八 */
    const val VALUE_BREAK_8 = 0x308
    /** 破线策略九 */
    const val VALUE_BREAK_9 = 0x309
    /** 上级强制结束下级 */
    const val VALUE_BREAK_HIGHER = 0x30A

    /** 失败 */
    const val VALUE_FAILED_1 = 0x401

    /** 破线策略二 周期结束 */
    const val VALUE_END_1 = 0x501
    /** 卖出后周期结束 */
    const val VALUE_END_2 = 0x502

    /** 未知买入 */
    const val VALUE_UNKNOWN_BUY = 0x601
    /** 未知卖出 */
    const val VALUE_UNKNOWN_SELL = 0x602

    /** 买入继承状态 */
    const val BUY_INHERIT_SHIFT = 24
    private const val BUY_INHERIT_MASK = 3.shl(BUY_INHERIT_SHIFT)

    private const val REMARK_NONE_1 = "无"
    private const val REMARK_ERROR_1 = "异常"
    private const val REMARK_INHERIT = "继承"
    private const val REMARK_INHERIT_MIN15 = "15启"
    private const val REMARK_START_1 = "启动"

    private const val REMARK_STAND_1 = "站稳策略一"
    private const val REMARK_STAND_2 = "站稳策略二"

    private const val REMARK_BREAK_1 = "破线策略一"
    private const val REMARK_BREAK_3 = "破线策略三"
    private const val REMARK_BREAK_4 = "破线策略四"
    private const val REMARK_BREAK_5 = "破线策略五"
    private const val REMARK_BREAK_6 = "破线策略六"
    private const val REMARK_BREAK_7 = "破线策略七"
    private const val REMARK_BREAK_8 = "破线策略八"
    private const val REMARK_BREAK_9 = "破线策略九"
    private const val REMARK_BREAK_HIGHER = "上级强制结束下级"

    private const val REMARK_FAILED_1 = "失败"

    private const val REMARK_END_1 = "破线策略二"
    private const val REMARK_END_2 = "卖出后结束"

    private const val REMARK_UNKNOWN_BUY = "未知买入"
    private const val REMARK_UNKNOWN_SELL = "未知卖出"


    /** 无*/
    const val VALUE_NONE = 0
    /** 启动 买 */
    const val VALUE_START = 1
    /** 破线 卖 */
    const val VALUE_BREAK = 2
    /** 站稳 买 */
    const val VALUE_STAND = 3
    /** 失败 卖 */
    const val VALUE_FAILED = 4
    /** 结束 束 */
    const val VALUE_END = 5

    const val DESC_NONE = "无"
    const val DESC_START = "启动"
    const val DESC_BREAK = "破线"
    const val DESC_STAND = "站稳"
    const val DESC_FAILED = "失败"
    const val DESC_END = "结束"
    const val DESC_ERROR = "异常"
    const val DESC_BUY = "买入"
    const val DESC_SELL = "卖出"

    fun getDescByValue(value: Int): String {
        return when (value) {
            VALUE_NONE_1 -> DESC_NONE
            VALUE_START_1 -> DESC_START
            VALUE_STAND_1 -> DESC_STAND
            VALUE_STAND_2 -> DESC_STAND
            VALUE_BREAK_1 -> DESC_BREAK
            VALUE_BREAK_3 -> DESC_BREAK
            VALUE_BREAK_4 -> DESC_BREAK
            VALUE_BREAK_5 -> DESC_BREAK
            VALUE_BREAK_6 -> DESC_BREAK
            VALUE_BREAK_7 -> DESC_BREAK
            VALUE_BREAK_8 -> DESC_BREAK
            VALUE_BREAK_9 -> DESC_BREAK
            VALUE_BREAK_HIGHER -> DESC_BREAK
            VALUE_FAILED_1 -> DESC_FAILED
            VALUE_END_1 -> DESC_END
            VALUE_END_2 -> DESC_END
            VALUE_UNKNOWN_BUY -> DESC_BUY
            VALUE_UNKNOWN_SELL -> DESC_SELL
            VALUE_ERROR_1 -> DESC_ERROR
            else -> DESC_NONE
        }
    }

    fun getRemarkByValue(value: Int): String {
        val isStart = (value and 0x00FFFFFF) in arrayOf(
            VALUE_START_1,
            VALUE_STAND_1,
            VALUE_STAND_2,
            VALUE_UNKNOWN_BUY
        )
        if (isStart && (value and BUY_INHERIT_MASK).shr(BUY_INHERIT_SHIFT) == 1) {
            //
            return REMARK_INHERIT
        }
        if (isStart && (value and BUY_INHERIT_MASK).shr(BUY_INHERIT_SHIFT) == 2) {
            // 15启
            return REMARK_INHERIT_MIN15
        }
        return when (value and 0x00FFFFFF) {
            VALUE_NONE_1 -> REMARK_NONE_1
            VALUE_START_1 -> REMARK_START_1
            VALUE_STAND_1 -> REMARK_STAND_1
            VALUE_STAND_2 -> REMARK_STAND_2
            VALUE_BREAK_1 -> REMARK_BREAK_1
            VALUE_BREAK_3 -> REMARK_BREAK_3
            VALUE_BREAK_4 -> REMARK_BREAK_4
            VALUE_BREAK_5 -> REMARK_BREAK_5
            VALUE_BREAK_6 -> REMARK_BREAK_6
            VALUE_BREAK_7 -> REMARK_BREAK_7
            VALUE_BREAK_8 -> REMARK_BREAK_8
            VALUE_BREAK_9 -> REMARK_BREAK_9
            VALUE_BREAK_HIGHER -> REMARK_BREAK_HIGHER
            VALUE_FAILED_1 -> REMARK_FAILED_1
            VALUE_END_1 -> REMARK_END_1
            VALUE_END_2 -> REMARK_END_2
            VALUE_ERROR_1 -> REMARK_ERROR_1
            VALUE_UNKNOWN_BUY -> REMARK_UNKNOWN_BUY
            VALUE_UNKNOWN_SELL -> REMARK_UNKNOWN_SELL
            else -> REMARK_NONE_1
        }
    }

    fun isBuyType(buyType: Int): Boolean {
        return (buyType and 0x00FFFFFF) in arrayOf(
            VALUE_START_1,
            VALUE_STAND_1,
            VALUE_STAND_2,
            VALUE_UNKNOWN_BUY
        )
    }

    fun isSellType(sellType: Int): Boolean {
        return (sellType and 0x00FFFFFF) in arrayOf(
            VALUE_BREAK_1,
            VALUE_BREAK_3,
            VALUE_BREAK_4,
            VALUE_BREAK_5,
            VALUE_BREAK_6,
            VALUE_BREAK_7,
            VALUE_BREAK_8,
            VALUE_BREAK_9,
            VALUE_FAILED_1,
            VALUE_END_1,
            VALUE_END_2,
            VALUE_BREAK_HIGHER,
            VALUE_UNKNOWN_SELL
        )
    }

    fun isErrorType(errorType: Int): Boolean {
        if (errorType == VALUE_ERROR_1) {
            return true
        }
        return false
    }

    fun getAlarmTypeValue(alarmType: Int): String {
        return when (alarmType and 0x00FFFFFF) {
            VALUE_NONE_1 -> ""
            VALUE_START_1 -> "启"
            VALUE_STAND_1 -> "稳"
            VALUE_STAND_2 -> "稳"
            VALUE_BREAK_1 -> "卖"
            VALUE_BREAK_3 -> "卖"
            VALUE_BREAK_4 -> "卖"
            VALUE_BREAK_5 -> "卖"
            VALUE_BREAK_6 -> "卖"
            VALUE_BREAK_7 -> "卖"
            VALUE_BREAK_8 -> "卖"
            VALUE_BREAK_9 -> "卖"
            VALUE_FAILED_1 -> "败"
            VALUE_END_1 -> "束"
            VALUE_END_2 -> "束"
            VALUE_BREAK_HIGHER -> "卖"
            else -> ""
        }
    }

    fun isAlarmTypeStart(alarmType: Int): Boolean {
        return alarmType and 0x00FFFFFF in arrayOf(
            VALUE_START_1
        )
    }

    fun isAlarmTypeStand(alarmType: Int): Boolean {
        return alarmType and 0x00FFFFFF in arrayOf(
            VALUE_STAND_1,
            VALUE_STAND_2
        )
    }

    fun isAlarmTypeBreak(alarmType: Int): Boolean {
        return alarmType and 0x00FFFFFF in arrayOf(
            VALUE_BREAK_1,
            VALUE_BREAK_3,
            VALUE_BREAK_4,
            VALUE_BREAK_5,
            VALUE_BREAK_6,
            VALUE_BREAK_7,
            VALUE_BREAK_8,
            VALUE_BREAK_9,
            VALUE_BREAK_HIGHER
        )
    }

    fun isAlarmTypeFailed(alarmType: Int): Boolean {
        return alarmType and 0x00FFFFFF in arrayOf(
            VALUE_FAILED_1
        )
    }

    fun isAlarmTypeEnd(alarmType: Int): Boolean {
        return alarmType and 0x00FFFFFF in arrayOf(
            VALUE_END_1,
            VALUE_END_2
        )
    }

}




